package com.octoo.it.swagger.handler;

import com.octoo.it.swagger.provider.SwaggerProvider;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import springfox.documentation.swagger.web.*;

import java.util.Optional;

/**
 * <p>
 * 说明
 * </p>
 *
 * @author miaoxiao
 * @since 2019-04-25
 */
@RestController
@RequestMapping("/swagger-resources")
@AllArgsConstructor
public class SwaggerHandler {

	private final SwaggerResourcesProvider swaggerProvider;

	@GetMapping("/configuration/security")
	public Mono<ResponseEntity<SecurityConfiguration>> securityConfiguration() {
		return Mono.just(new ResponseEntity<>(
			Optional.ofNullable(SecurityConfigurationBuilder.builder().build()).orElse(SecurityConfigurationBuilder.builder().build()), HttpStatus.OK));
	}

	@GetMapping("/configuration/ui")
	public Mono<ResponseEntity<UiConfiguration>> uiConfiguration() {
		return Mono.just(new ResponseEntity<>(
			Optional.ofNullable(UiConfigurationBuilder.builder().build()).orElse(UiConfigurationBuilder.builder().build()), HttpStatus.OK));
	}

	@GetMapping
	public Mono<ResponseEntity> swaggerResources() {
		return Mono.just((new ResponseEntity<>(swaggerProvider.get(), HttpStatus.OK)));
	}
}
